package oop4.graph01;

public class Triangle extends Graph {
    //关于类的属性，要常用封装，很重要
    private double l1;
    private double l2;
    private double l3;
    private boolean s = true;

    public Triangle() {
    }

    public Triangle(double l1, double l2, double l3) {
        this.l1 = l1;
        this.l2 = l2;
        this.l3 = l3;
    }

    public double getL1() {
        return l1;
    }

    public void setL1(double l1) {
        this.l1 = l1;
    }

    public double getL2() {
        return l2;
    }

    public void setL2(double l2) {
        this.l2 = l2;
    }

    public double getL3() {
        return l3;
    }

    public void setL3(double l3) {
        this.l3 = l3;
    }

    public boolean isS() {
        return s;
    }

    public void setS(boolean s) {
        this.s = s;
    }

    @Override
    public double calcArea() {
        if (l1 + l2 <= l3 || l1 + l3 <= l2 || l2 + l3 <= l1) {
            System.out.println("存在两边之和不大于第三边的情况，不构成三角形");
            s = false;
            return 0;
        }
        double p = calcRound() / 2;
        return Math.sqrt(p * (p - l1) * (p - l2) * (p - l3));
    }

    @Override
    public double calcRound() {
        if (s == false) {
            return 0;
        }
        return l1 + l2 + l3;
    }

    @Override
    public String toString() {
        return "三角形,三条边分别是" + l1 + "," + l2 + "," + l3;
    }
}
